package com.leet.code.simple_array;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:    1431.拥有最多糖果的孩子
 * @author: WYG
 * @time: 2021/1/4 9:29
 */

public class KidsWithCandies {

    public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
        List<Boolean> res = new ArrayList<>();
        int max = 0;
        //首先找到candies中的最大值
        for (int i = 0; i < candies.length; i++) {
            if (candies[i] > max) {
                max = candies[i];
            }
        }
        //遍历每个元素,如果candies[i]+extraCandies大于等于max的话,那说明满足条件,为true,否则为false
        for (int i = 0; i < candies.length; i++) {
            if (candies[i] + extraCandies >= max) {
                res.add(true);
            } else {
                res.add(false);
            }

        }
        return res;
    }

    public List<Boolean> slow_kidsWithCandies(int[] candies, int extraCandies) {
        List<Boolean> res = new ArrayList<>();
        for (int i = 0; i < candies.length; i++) {
            Boolean flag = true;
            for (int j = 0; j < candies.length; j++) {
                if (i != j && (candies[i] + extraCandies) < candies[j]) {
                    flag = false;
                }
            }
            res.add(flag);
        }
        return res;
    }
}
